package cn.ctvonline.android.kaopu.fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

import cn.ctvonline.android.kaopu.R;
import cn.ctvonline.android.kaopu.base.AppApplication;
import cn.ctvonline.android.kaopu.base.BaseFragment;
import cn.ctvonline.android.kaopu.widget.view.ZoomableImageView;

/**
 * A placeholder fragment containing a simple view.
 */
public class ImageShowActivityFragment extends BaseFragment {
    protected static String TAG = BaseFragment.class.getName();
    private ZoomableImageView imageShowZiv;
    private String imagePath;
    SimpleImageLoadingListener simpleImageLoadingListener;

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    public void reloadImage() {
        ImageLoader.getInstance().displayImage(imagePath, imageShowZiv, AppApplication.getInstance().getOptions(), simpleImageLoadingListener);
    }

    public ImageShowActivityFragment() {

    }

    private boolean zivDoubleClicked = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_image_show, container, false);
        imageShowZiv = (ZoomableImageView) view.findViewById(R.id.image_show_ziv);
        imageShowZiv.setOnDoubleClickListener(new ZoomableImageView.OnDoubleClickListener() {
            @Override
            public void onDoubleClick(View view) {
                if (zivDoubleClicked) {
                    imageShowZiv.zoomToMin();
                    zivDoubleClicked = false;
                } else {
                    imageShowZiv.zoomToMax();
                    zivDoubleClicked = true;
                }
            }
        });
        simpleImageLoadingListener = new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                ((ZoomableImageView) view).setBitmap(loadedImage);
            }
        };
        setImagePath("http://www.txlz.net/Photo/UploadPhotos/201009/2010090216494857.jpg");
        ImageLoader.getInstance().displayImage(imagePath, imageShowZiv, AppApplication.getInstance().getOptions(), simpleImageLoadingListener);
        return view;
    }

}
